import {
  ElLoading
} from 'element-plus'
let loading;
export default {
  namespaced: true,
  state: {
    $loading: false,
  },
  mutations: {
    SET_LOADING(state, payload) {
      if (payload) {
        loading = ElLoading.service({
          lock: true,
          text: '获取数据中...',
          spinner: 'el-icon-loading',
          background: 'rgba(255, 255, 255, 0.5)',
        });
      } else {
        if (process.env.VUE_APP_ISMOCK == 1) {
          setTimeout(() => {
            loading && loading.close()
          }, 1000);
        } else {
          loading && loading.close()
        }
      }
      state.$loading = payload
    }
  },
  getters: {
    $loading: state => state.$loading
  }
}